﻿Public Class u_taikhoan
    Private Sub LoadData()
        Dim cc As New DangNhapBUS
        dgvDSTK.DataSource = cc.GetTaiKhoan
        Dim nv As New NhanVienBUS
        cbxTenNV.DataSource = nv.GetNhanVien
        cbxTenNV.DisplayMember = "TenNV"
        cbxTenNV.ValueMember = "MaNV"
        cbxTenNV.SelectedIndex = 0
    End Sub

    Private Sub gvDSTK_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles gvDSTK.FocusedRowChanged
        txtMaTaiKhoan.Text = gvDSTK.GetRowCellValue(gvDSTK.FocusedRowHandle, "MaTaiKhoan")
        txtID.Text = gvDSTK.GetRowCellValue(gvDSTK.FocusedRowHandle, "TenDangNhap")
        txtMK.Text = gvDSTK.GetRowCellValue(gvDSTK.FocusedRowHandle, "MatKhau")
        cbxTenNV.Text = gvDSTK.GetRowCellValue(gvDSTK.FocusedRowHandle, "MaNV")
        ' NTNS.Value = Date.Parse(gvDSTK.GetRowCellValue(gvDSTK.FocusedRowHandle, "NTNS").ToString)
        txtDiaChi.Text = gvDSTK.GetRowCellValue(gvDSTK.FocusedRowHandle, "DiaChi")
    End Sub

    Private Sub u_taikhoan_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LoadData()
    End Sub

    Private Sub btnThem_Click(sender As Object, e As EventArgs) Handles btnThem.Click
        Dim newTK As New DangNhapDTO
        newTK.MaTaiKhoan = txtMaTaiKhoan.Text
        newTK.ID = txtID.Text
        newTK.PW = txtMK.Text
        newTK.DiaChi = txtDiaChi.Text
        newTK.NTNS = NTNS.Value.Date
        newTK.MaNV = cbxTenNV.SelectedValue
        Dim tkBUS As New DangNhapBUS
        tkBUS.AddTaiKhoan(newTK)
        LoadData()
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Dim delTK As New DangNhapDTO
        delTK.MaTaiKhoan = gvDSTK.GetRowCellValue(gvDSTK.FocusedRowHandle, "MaTaiKhoan")
        Dim tkBUS As New DangNhapBUS
        tkBUS.DelTaiKhoan(delTK)
        LoadData()
    End Sub
    Private Sub btnCapNhat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapNhat.Click
        Dim newTK As New DangNhapDTO
        newTK.MaTaiKhoan = gvDSTK.GetRowCellValue(gvDSTK.FocusedRowHandle, "MaTaiKhoan")
        newTK.ID = txtID.Text
        newTK.PW = txtMK.Text
        newTK.MaNV = cbxTenNV.Text
        newTK.DiaChi = txtDiaChi.Text
        Dim tkBUS As New DangNhapBUS
        tkBUS.UpdateTaiKhoan(newTK)
        LoadData()
    End Sub
End Class
